package NIO;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Scanner;
public class readfile {

	static String pathfile;
	private static Scanner sc;
	public static void setpath(String a){
	    pathfile=a;
	}
	public static void read() throws IOException{
		
		FileInputStream f =new FileInputStream(pathfile);
		FileChannel inChannel =f.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        while(inChannel.read(buffer) > 0)
        {
            buffer.flip();
            for (int i = 0; i < buffer.limit(); i++)
            {
                System.out.print((char) buffer.get());
            }
            buffer.clear(); // do something with the data and clear/compact it.
        }
        inChannel.close();
        f.close();
	}
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		System.out.println("nhap duong dan file:");
		sc = new Scanner(System.in);
		setpath(sc.nextLine());
		read();
	}

}
